﻿using System;
using System.Collections.Generic;
using System.Linq;
using FinancePortal.Business.Infraestructure;
using FinancePortal.Business.Repository;
using FinancePortal.Domain.Model;

namespace FinancePortal.Business.Implementation
{
    public class ActivityScheduleRepository : RepositoryBase<ActivitySchedule>, IActivityScheduleRepository
    {
        public ActivityScheduleRepository(IUnitOfWork uow)
            : base(uow)
        { }

        public IList<ActivitySchedule> GetByResource(int resourceId, DateTime fromDate, DateTime toDate)
        {
            var list = (from a in GetAll()
                    where (a.Owner.Id == resourceId
                        || a.Participants.Any(r => r.Id == resourceId))
                        && a.FromDate >= fromDate
                        && a.ToDate <= toDate
                    select a).ToList();

            return list;
        }

    }
}
